import QtQuick 1.1
import com.nokia.meego 1.0

SelectionDialog {
    id: singleSelectionDialog
    titleText: "选择字体"
    selectedIndex: 0

    delegate: Rectangle {
        id: fontDelegate
        width: parent.width
        height: 100
        color: mouseArea.pressed ? "grey" : "transparent"
        Label {
            id: fontName
            anchors.verticalCenter: parent.verticalCenter
            anchors.left: parent.left
            verticalAlignment: Text.AlignVCenter
            text: model.name
            font.family: model.name
            width: parent.width
            height: parent.height
            font.pixelSize: 40
            color: mouseArea.pressed ? "black" : "white"
        }
        MouseArea {
            id: mouseArea
            anchors.fill: parent
            onClicked: {
                singleSelectionDialog.selectedIndex = index
                singleSelectionDialog.accept()
            }
        }
    }


    function load() {
        listModel.clear()
        var fontFamilyList = new Array()
        fontFamilyList =  engine.fontFamilies()
        console.log("fontFamily length", fontFamilyList.length)
        for (var i = 0; i < fontFamilyList.length; i++) {
            console.log("add family", fontFamilyList[i])
            listModel.append({"name": fontFamilyList[i]})
        }
    }

    model: ListModel {
        id: listModel
    }
    Component.onCompleted: {
        load()
    }
}
